import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document, Types } from 'mongoose';

export type JourneyDocument = Journey & Document;

@Schema()
export class Journey {
  @Prop({ required: false, type: Types.ObjectId, default: () => new Types.ObjectId() })
  _id: Types.ObjectId;

  @Prop({ required: true, unique: false })
  publisher_id: string

  @Prop({ required: true, unique: false })
  departure: string;

  @Prop({ required: true, unique: false })
  destination: string;

  @Prop({ required: false, unique: false })
  date: string;

  @Prop({ required: false, unique: false })
  time: string;

  @Prop({ required: false, unique: false })
  seats: number;

  @Prop({ required: false, unique: false })
  price: string;

  @Prop({ required: false, unique: false })
  wechat: string;

  @Prop({ required: false, unique: false })
  phone: string;

  @Prop({ required: false, unique: false })
  description: string;

  @Prop({ required: false, unique: false, default: Date.now })
  created_at: Date;
}

export const JourneySchema = SchemaFactory.createForClass(Journey);

// 添加文本索引
JourneySchema.index({ departure: 'text', destination: 'text' });